package o;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import huawei.widget.HwButton;
import java.util.ArrayList;
import java.util.List;
import o.dqw.c;
import o.epq.e;
import o.ewm.n;

public class due {
    private OnDismissListener ˊ;
    private boolean ˋ = false;
    private b ˎ = new b();
    private cki ˏ;

    public interface d {
        void ॱ(SessionDownloadTask sessionDownloadTask);
    }

    class b {
        final /* synthetic */ due ˏ;

        final class a implements o.ckh.a {
            final /* synthetic */ b ˏ;
            private dua ॱ;

            public a(b bVar, dua o_dua) {
                this.ˏ = bVar;
                this.ॱ = o_dua;
            }

            public void ˏ(AlertDialog alertDialog, com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a aVar, int i) {
                if (aVar.ˏ() == null) {
                    Logger.e("BatchUpClickUtil", "view is null");
                    return;
                }
                dui o_dui = new dui();
                o_dui.ˎ(this.ॱ.ˋ());
                o_dui.ˋ(this.ॱ.ˏ());
                o_dui.ˏ(this.ॱ.ˎ());
                if (-1 == i) {
                    this.ˏ.ˎ(aVar.ˏ(), alertDialog.getOwnerActivity(), o_dui, true);
                } else if (-2 == i) {
                    this.ˏ.ˎ(aVar.ˏ(), alertDialog.getOwnerActivity(), o_dui, false);
                }
            }
        }

        final class b implements OnDismissListener {
            final /* synthetic */ b ˏ;
            private dua ॱ;

            public b(b bVar, dua o_dua) {
                this.ˏ = bVar;
                this.ॱ = o_dua;
            }

            public void onDismiss(DialogInterface dialogInterface) {
                if (this.ॱ != null && this.ॱ.ॱ() != null) {
                    this.ॱ.ॱ().ॱ();
                }
            }
        }

        private b(due o_due) {
            this.ˏ = o_due;
        }

        private void ˊ() {
            new Thread(this, "pauseAllTask") {
                final /* synthetic */ b ˎ;

                public void run() {
                    List<ApkUpgradeInfo> arrayList = new ArrayList();
                    arrayList.addAll(dss.ॱ().ˎ(true, 1));
                    arrayList.addAll(dss.ॱ().ॱ(true, 1));
                    for (ApkUpgradeInfo ᐝ : arrayList) {
                        SessionDownloadTask ˋ = dvt.ˏ().ˋ(ᐝ.ᐝ());
                        if (ˋ != null) {
                            dvt.ˏ().ˏ(ˋ.ʾ());
                        }
                    }
                    ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(e.ˊ));
                }
            }.start();
        }

        private void ˎ(View view, Context context, dui o_dui, boolean z) {
            if (o_dui == null) {
                Logger.e("BatchUpClickUtil", "param is null");
                return;
            }
            dvr.ॱ(view, z);
            if (z) {
                dub.ˋ(o_dui.ˊ(), this.ˏ.ॱ());
                dss.ॱ().ˏ(context, czt.ˊ, null);
                return;
            }
            ˋ(o_dui.ˎ(), o_dui.ˋ());
            dss.ॱ().ˏ(context, czt.ˊ, null);
        }

        private void ˏ() {
            if (this.ˏ.ˊ() != null) {
                this.ˏ.ˊ().ˋ();
            }
        }

        private void ॱ(Activity activity, List<ApkUpgradeInfo> list, List<ApkUpgradeInfo> list2, boolean z) {
            if (dvr.ˏ(activity, true)) {
                dub.ˋ(false, this.ˏ.ॱ());
                dss.ॱ().ˏ(activity, czt.ˊ, null);
                ˏ();
                return;
            }
            ˎ(activity, (List) list, (List) list2, z);
        }

        private void ˎ(Activity activity, List<ApkUpgradeInfo> list, List<ApkUpgradeInfo> list2, boolean z) {
            long ॱ = dvr.ॱ(list2);
            dua o_dua = new dua();
            o_dua.ˎ(list);
            o_dua.ˋ(list2);
            o.ckh.a aVar = new a(this, o_dua);
            OnDismissListener bVar = new b(this, o_dua);
            if (dvr.ˏ(activity)) {
                dvr.ˋ(activity, ॱ, aVar, bVar);
            } else if (dvr.ॱ(activity) && !z) {
                ˋ(list2, list);
                dss.ॱ().ˏ(activity, czt.ˊ, null);
                ˏ();
            } else if (dvr.ॱ(activity) && z) {
                dvr.ˋ(activity, ॱ, aVar, bVar);
            } else if (dvr.ˋ(activity)) {
                dvr.ˏ(activity, ॱ, aVar, bVar);
            }
        }

        private void ˋ(List<ApkUpgradeInfo> list, List<ApkUpgradeInfo> list2) {
            for (ApkUpgradeInfo apkUpgradeInfo : list) {
                if (apkUpgradeInfo == null || TextUtils.isEmpty(apkUpgradeInfo.ᐝ())) {
                    String str;
                    String str2 = "BatchUpClickUtil";
                    StringBuilder append = new StringBuilder().append("reserveDownload, apkUpgradeInfo = ").append(apkUpgradeInfo).append(", apkUpgradeInfo.package_ = ");
                    if (apkUpgradeInfo == null) {
                        str = null;
                    } else {
                        str = apkUpgradeInfo.ᐝ();
                    }
                    Logger.ˎ(str2, append.append(str).toString());
                } else {
                    SessionDownloadTask ˋ = dvt.ˏ().ˋ(apkUpgradeInfo.ᐝ());
                    if (ˋ == null) {
                        due.ॱ(apkUpgradeInfo, new d(this) {
                            final /* synthetic */ b ˎ;

                            {
                                this.ˎ = r1;
                            }

                            public void ॱ(SessionDownloadTask sessionDownloadTask) {
                                if (sessionDownloadTask != null) {
                                    dvt.ˏ().ॱ(sessionDownloadTask);
                                }
                            }
                        });
                    } else if (ˋ.ˈ() == 6) {
                        dvt.ˏ().ॱ(ˋ);
                    }
                }
            }
            this.ˏ.ˊ(list2);
            ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(e.ˊ));
            dwb.ˎ(list.size());
        }
    }

    public static void ॱ(final ApkUpgradeInfo apkUpgradeInfo, final d dVar) {
        new dqw().ˏ(dqw.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ॱʽ(), apkUpgradeInfo.ʿ() + ""), new c() {
            public void ˋ(SessionDownloadTask sessionDownloadTask) {
                if (apkUpgradeInfo.ॱʽ() == 0) {
                    SplitTask splitTask = new SplitTask();
                    splitTask.ˋ(apkUpgradeInfo.ˈ());
                    splitTask.ˊ(apkUpgradeInfo.ʾ());
                    splitTask.ˋ(apkUpgradeInfo.ʻॱ());
                    splitTask.ˊॱ(apkUpgradeInfo.ᐝ());
                    sessionDownloadTask.ˏ(splitTask);
                }
                sessionDownloadTask.ˊ(apkUpgradeInfo.ˈ());
                sessionDownloadTask.ʼ(apkUpgradeInfo.ᐝ());
                sessionDownloadTask.ॱॱ(apkUpgradeInfo.ˊ());
                sessionDownloadTask.ॱ(apkUpgradeInfo.ॱ());
                sessionDownloadTask.ʽ(apkUpgradeInfo.ॱᐝ());
                sessionDownloadTask.ˏ(apkUpgradeInfo.ˊᐝ());
                sessionDownloadTask.ʻ(apkUpgradeInfo.ʿ());
                sessionDownloadTask.ॱ(apkUpgradeInfo.ˏˎ());
                sessionDownloadTask.ॱˊ(apkUpgradeInfo.ॱʽ());
                if (apkUpgradeInfo.ʼ() > 0) {
                    List ᐝˊ = sessionDownloadTask.ᐝˊ();
                    if (!CollectCheck.isEmpty(ᐝˊ)) {
                        splitTask = (SplitTask) ᐝˊ.get(0);
                        splitTask.ˏ(apkUpgradeInfo.ॱॱ());
                        splitTask.ॱ(apkUpgradeInfo.ʼ());
                        splitTask.ˎ(apkUpgradeInfo.ˈ());
                        splitTask.ˋ(apkUpgradeInfo.ʽॱ());
                    }
                    sessionDownloadTask.ˊ(apkUpgradeInfo.ʽॱ());
                }
                if (1 == apkUpgradeInfo.ˏॱ()) {
                    sessionDownloadTask.ˏ(2);
                }
                if (dVar != null) {
                    dVar.ॱ(sessionDownloadTask);
                }
            }

            public void ॱ() {
                Logger.e("BatchUpClickUtil", "getBundleInfo fail.");
                if (dVar != null) {
                    dVar.ॱ(null);
                }
            }
        });
    }

    public boolean ˊ(Activity activity, HwButton hwButton) {
        dss.ॱ().ॱˋ();
        if (!ॱ() && hwButton != null && (hwButton.getTag() instanceof czn) && ((czn) hwButton.getTag()).ˋ) {
            Logger.ˎ("BatchUpClickUtil", "pauseAllUpdateTask");
            this.ˎ.ˊ();
            return true;
        } else if (dss.ॱ().ˋ(true, 1) > 0) {
            List<ApkUpgradeInfo> arrayList = new ArrayList();
            List arrayList2 = new ArrayList();
            if (!ˊ(activity, arrayList, arrayList2)) {
                return false;
            }
            if (hwButton != null && (hwButton.getTag() instanceof czn) && ((czn) hwButton.getTag()).ˏ) {
                Logger.ˎ("BatchUpClickUtil", "continue Download AllUpdateTask");
                if (!arrayList.isEmpty()) {
                    for (ApkUpgradeInfo apkUpgradeInfo : arrayList) {
                        dsl.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ˊ(), apkUpgradeInfo.ॱᐝ(), 0, coc.ˎ);
                    }
                }
                ˎ(activity, arrayList, arrayList2, true);
                return true;
            }
            ˎ(activity, arrayList, arrayList2, false);
            return true;
        } else {
            dss.ॱ().ʾ();
            return false;
        }
    }

    private boolean ˊ(Activity activity, List<ApkUpgradeInfo> list, List<ApkUpgradeInfo> list2) {
        for (ApkUpgradeInfo apkUpgradeInfo : dss.ॱ().ˎ(true, 1)) {
            if (apkUpgradeInfo != null) {
                if (1 == apkUpgradeInfo.ˏॱ()) {
                    dss.ॱ().ˏ(activity);
                    return false;
                }
                int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(apkUpgradeInfo.ᐝ());
                if (ˋ == 2 || ˋ == 1) {
                    list.add(apkUpgradeInfo);
                } else if (!(ˋ == 10 || ˋ == 11)) {
                    list2.add(apkUpgradeInfo);
                }
            }
        }
        return true;
    }

    private void ˎ(Activity activity, List<ApkUpgradeInfo> list, List<ApkUpgradeInfo> list2, boolean z) {
        if (!doo.ˊ(activity)) {
            for (ApkUpgradeInfo apkUpgradeInfo : list) {
                dsl.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ˊ(), apkUpgradeInfo.ॱᐝ(), 0, coc.ˎ);
            }
            if (!list2.isEmpty()) {
                evk.ˋ(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getResources().getString(n.ʹˊ), 0).ˋ();
                dss.ॱ().ˏ(activity, czt.ˊ, null);
            }
            this.ˎ.ˏ();
        } else if (!list2.isEmpty() || list.isEmpty()) {
            this.ˎ.ॱ(activity, list, list2, z);
        } else {
            ˊ(list);
            this.ˎ.ˏ();
        }
    }

    public void ˎ(OnDismissListener onDismissListener) {
        this.ˊ = onDismissListener;
    }

    private void ˊ(List<ApkUpgradeInfo> list) {
        for (ApkUpgradeInfo apkUpgradeInfo : list) {
            int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(apkUpgradeInfo.ᐝ());
            if (ˋ == 1 || ˋ == 2) {
                dsl.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ˊ(), apkUpgradeInfo.ॱᐝ(), 0, coc.ˎ);
            }
        }
    }

    private boolean ॱ() {
        return this.ˋ;
    }

    public void ˋ(boolean z) {
        this.ˋ = z;
    }

    private cki ˊ() {
        return this.ˏ;
    }

    public void ˏ(cki o_cki) {
        this.ˏ = o_cki;
    }
}
